package com.gitee.clarence.util;

import java.util.HashMap;
import java.util.Map;

import com.gitee.clarence.common.dataobject.vo.ResultVO;
import com.gitee.clarence.common.enums.ResultEnum;

/**
 * @Author: luopeng
 * @Date: 2018年3月23日
 * @Description:
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public class ResultVOUtil {

	public static <T> ResultVO<T> returnSuccess(T object) {
		ResultVO resultVO = new ResultVO();
		resultVO.setCode(0);
		resultVO.setMsg("success");
		resultVO.setData(object);
		return resultVO;
	}

	public static <T> ResultVO<T> returnSuccess(String key, T object) {
		ResultVO resultVO = new ResultVO();
		resultVO.setCode(0);
		resultVO.setMsg("success");
		Map<String, Object> map = new HashMap<>();
		map.put(key, object);
		resultVO.setData(map);
		return resultVO;
	}

	public static ResultVO returnSuccess() {
		return returnSuccess(null);
	}

	public static ResultVO returnFail(Integer code, String msg) {
		ResultVO resultVO = new ResultVO();
		resultVO.setCode(code);
		resultVO.setMsg(msg);
		return resultVO;
	}

	public static <T> ResultVO<T> returnFail(Integer code, String msg, T object) {
		ResultVO resultVO = new ResultVO();
		resultVO.setCode(code);
		resultVO.setMsg(msg);
		resultVO.setData(object);
		return resultVO;
	}

	public static ResultVO returnFail() {
		return returnFail(ResultEnum.FAIL);
	}

	public static <T> ResultVO returnFail(T object) {
		return returnFail(ResultEnum.FAIL, object);
	}

	public static ResultVO returnFail(ResultEnum resultEnum) {
		return returnFail(resultEnum, null);
	}

	public static <T> ResultVO<T> returnFail(ResultEnum resultEnum, T object) {
		ResultVO resultVO = new ResultVO();
		resultVO.setCode(resultEnum.getCode());
		resultVO.setMsg(resultEnum.getMessage());
		resultVO.setData(object);
		return resultVO;
	}
}
